﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using KaoQin.BLL;
using KaoQin.Common;
using KaoQin.Model;

namespace KaoQin.WPFApp.sys.User
{
    /// <summary>
    /// MofifyUserPwd.xaml 的交互逻辑
    /// </summary>
    public partial class MofifyUserPwd : Window
    {
        public MofifyUserPwd()
        {
            InitializeComponent();
        }

        private SysUsersInfo UserInfo = null;

        public MofifyUserPwd(SysUsersInfo user)
        {
            InitializeComponent();

            this.UserInfo = user;
            txtReadName.Text = this.UserInfo.RealName;
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtoldPwd.Password))
                {
                    MessageBox.Show("原密码不能为空");
                    return;

                }
                if (string.IsNullOrEmpty(txtnewPwd.Password))
                {
                    MessageBox.Show("新密码不能为空");
                    return;
                }
                if (txtoldPwd.Password != this.UserInfo.Password)
                {
                    MessageBox.Show("原密码错误");
                    return;
                }

                this.UserInfo.Password=txtnewPwd.Password;

                new SysUsers().Update(this.UserInfo);
                MessageBox.Show("密码修改成功");
                
            }
            catch (Exception ex)
            {
                MessageBox.Show("密码修改失败:" + ex.Message);
            }
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
